<template>
	<view class="pages">
		<view class="calendar">
			<view class="calendar_title">每日签到</view>
			<view class="calendar_text display_between">

				<view class="" v-for="(item, index) in week" :key="item.id">
					<!-- <text v-if=" num!=item.id || !signState">{{ item.beizhu }}</text> -->
					<text v-if="index + 1 > signedDays">{{ item.beizhu }}</text>
					<u-icon v-else name="checkmark-circle-fill" size="40rpx" color="#000"></u-icon>
				</view>
			</view>
			<view class="calendar_text display_between">
				<!-- <text>1</text>
				<text>2</text>
				<text>3</text>
				<text>4</text>
				<text>
					<u-icon name="gift-fill" size="50rpx" color="#fff"></u-icon>
				</text>
				<text>6</text>
				<text>7</text> -->
				<view class="" v-for="(item, index) in week" :key="item.id">
					<text v-if="gift!=item.id">{{item.zhi}}</text>
					<u-icon v-else name="gift-fill" size="50rpx" color="#fff"></u-icon>
				</view>
			</view>
		</view>

		<view class="integral">
			<view class="integral_title color_666">
				我的积分
			</view>
			<view class="integral_but display_between">
				<view class="integral_num">
					<text>{{interData.integral}}</text>
					<text>分</text>
				</view>
				<!-- <view class="integral_right display_center">
					<text>已累计签到</text>
					<text>2</text>
					<text>天</text>
				</view> -->
				<view :class="!signState?'integral_right2 display_center':'integral_right1 display_center'"
					@click="butSign">
					<view v-if="signState">
                        <text class="inte-t-1">已累计签到</text>
                        <text class="inte-t-2">{{ signedDays }}</text>
                        <text class="inte-t-1">天</text>
                    </view>
					<view v-else>签到</view>
				</view>
			</view>
			<view class="borders"></view>
		</view>
		<view class="PointsDetails">
			<view class="PointsDetails_title">
				积分明细
			</view>
			<mescroll-body class="mescroll-body" @init="mescrollInit" @down="downCallback" @up="upCallback"
				:down="downOption" :up="upOption" top="0rpx">
				<view class="scroll-view-item PointsDetails_list display_between" v-for="item in integ" :key="item.id">
					<view class="list_left">
						<text>{{item.type_name}}</text>
						<view>{{item.time}}</view>
					</view>
					<view class="list_right" v-if="item.type_int">+{{item.sum}}</view>
					<view class="list_right" v-else>-{{item.sum}}</view>
				</view>
			</mescroll-body>

		</view>
        
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";

    import {
        inte_user_qian_sum, integral_user_list_json, integral_user_inc, integral_suan, integral_user_inc_int
    } from "@/api/useryk.js"
    import {Resource_url, Http_url} from "@/config/config.js"
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
                Resource_url,
				week: [], //签到列表
				gift: 7, //签到奖励
				num: new Date().getDay() ? new Date().getDay() : 7, //获取当前星期数
				signState: 0, //判断当前用户是否签到
				
				// buts: {
				// 	user_id: '1',
				// 	token: '',
				// 	sum: 0
				// }, //点击签到接口参数
				integral: {
					user_id: '1',
					token: '',
					list_rows: '10',
					page: 1
				}, //积分明细接口参数
				integ: [], //积分列表数据
				triggered: false,
				list: [{}],
				// Member: {
				// 	token: '',
				// 	user_id: 1
				// },
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {

				},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					},
					textNoMore: '没有更多了'
				},
                // 已签到天数
                signedDays: 0 
			}
		},
		created() {
			
			// this.setMember()
		},
		onLoad() {
            this.getUserInte()
			this.setIntegral()
			this.setSign()
		},
        computed: {
            interData(){
                return this.$store.state.app.userInfou || {}
            }
        },
		methods: {

			//获取用户积分信息
			// setMember() {
			// 	// this.Member.token = this.$u.vuex.get('user.token')
			// 	console.log(this.$u.vuex.get('user.userInfo'),'kkk');
			// 	this.$u.request('member.setMember',{
			// 		user_id:this.$u.vuex.get('user.userInfo').user_id
			// 	}).then(res => {
			// 		console.log(res, 'this.Member');
			// 		this.interData = res.data
			// 	})
			// },
            
			// 获取用户已经签到多少天
			getUserInte() {
				inte_user_qian_sum({
                    user_id: this.interData.id
                }).then(res => {
                    this.signedDays = res.count
				})
			},
			//获取签到列表
			setIntegral() {
				integral_suan().then(res => {
					this.week = res.data
				})
			},
			//获取用户是否签到
			setSign() {
				integral_user_inc_int({
					user_id: this.interData.id
				}).then(res => {
					this.signState = res.qd_int
				})
			},
			//点击签到
			butSign() {
					
				if(this.signState){
					return
				}else{
                    // console.log(this.num)
					// this.buts.token = this.$u.vuex.get('user.token');
					// let sum = this.week.find(item => item.id == this.num).zhi
                    // console.log(this.signedDays)
					// let sum = this.week[this.signedDays].zhi

					integral_user_inc({
                        user_id: this.interData.id,
						// sum: sum
					}).then(res => {
			
                        // this.setMember()
                         // this.$u.vuex.dispatch('user/getUserInfo')
                         this.$store.dispatch('USERINFO')
                        this.downCallback()
                        // this.integralList()
                        this.getUserInte()
                        this.setSign()
                        this.$refs.uToast.show({
                            type: 'success',
                            message: '签到成功'
                        })
					})
				}
				
			},
			/*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},

			// 下拉刷新的回调, 重置列表为第一页 (此处可删,mixins已默认)
			downCallback() {
				this.integ = []
				this.mescroll.resetUpScroll();
			},
			/*上拉加载的回调*/
			upCallback(page) {
				let pageNum = page.num; // 页码, 默认从1开始
				let pageSize = page.size; // 页长, 默认每页10条
				integral_user_list_json( {
					list_rows: pageSize,
					page: pageNum,
					sum: 0,
                    user_id: this.interData.id
				}).then(res => {
					const list = res.data.map(item => {
						return {
							...item,
							// files: this.$evns + item.files
							files:Resource_url + item.files
						}
					})
					this.integ = this.integ.concat(list)
					this.mescroll.endSuccess(list.length, list.length, list.length >= page.size)

				}).catch(e => {
					this.$u.toast(e.message || '')
					this.mescroll.endErr()
				})

			}
		}
	}
</script>

<style scoped lang="scss">
 @import '@/libs/PublicStyle.scss';
    page{
        background-color: #FFF;
    }
	.pages {
		padding: 20rpx 0;
	}

	.calendar {
		margin: 0rpx 15rpx;
		padding: 20rpx 30rpx;
		// width: 660rpx;
		height: 240rpx;
		border-radius: 20rpx;
		color: #fff;
		background-color: #B29062;
		// background-color: #999999;


	}

	.calendar_text {
		// margin: 55rpx 0;
		padding: 0rpx 0 5rpx 0;

		>view {
			display: flex;
			justify-content: center;
			width: 13%;
		}
	}

	.integral {
		padding: 10rpx 25rpx;
        margin-top: 30rpx;
	}

	.integral_title {
		width: 100%;
		font-size: 26rpx;
		margin-bottom: 10rpx;

	}

	.integral_num>text:nth-child(1) {
		font-size: 44rpx;
        font-weight: 500;
	}

	.integral_num>text:nth-child(2) {
		font-size: 26rpx;
	}

	.integral_right1 {
		// width: 150rpx;
		height: 70rpx;
		background-color: #e8e8e8;
		color: #999;
		border-radius: 10rpx;
		font-size: 32rpx;
        padding: 0 25rpx;
        
        .inte-t-2{
            font-size: 36rpx;
            color: red !important;
        }
	}

	.integral_right2 {
		// width: 150rpx;
		height: 70rpx;
		background: #B29062;
		color: #fff;
		border-radius: 10rpx;
		font-size: 32rpx;
        padding: 0 25rpx;
	}

	// .integral_right>text:nth-child(2){
	// 	margin-top: -15rpx;
	// 		color: #f56e6e;
	// 		font-size: 45rpx;
	// }
	.borders {
		margin: 30rpx 0;
		width: 100%;
		height: 10rpx;
		background-color: #F2F2F2;
	}

	.PointsDetails {
		// padding: 0 30rpx;
	}

	.PointsDetails_title {
		margin: 0 30rpx;
		padding-bottom: 20rpx;
		width: 710rpx;
		font-size: 36rpx;
		font-weight: 600;
		margin-bottom: 10rpx;
	}

	.PointsDetails_list {
		margin: 30rpx 30rpx;
		// width: 650rpx;
        
		padding: 20rpx 35rpx;
		// height: 80rpx;
		box-shadow: 0 0 20rpx 0rpx  #dadada;
        border-radius: 15rpx;
	}

	.list_left>view {
		margin-top: 20rpx;
		font-size: 24rpx;
		color: #9FA09F;
	}

	.list_right {
		font-size: 35rpx
	}
</style>